
    <!DOCTYPE html>
    <html lang="zh-CN">
    <head>
      <meta charset="UTF-8">
      <meta name="viewport" content="width=device-width, initial-scale=1.0">
      <title>Java 并发库中有哪些线程池？它们之间有何区别？ - 学习卡片</title>
      <style>
        body { font-family: sans-serif; background-color: #f0f8ff; color: #333; display: flex; flex-direction: column; align-items: center; padding: 50px 20px; }
        .header h1 { font-size: 32px; }
        .grid-container { display: grid; grid-template-columns: repeat(3, 1fr); gap: 28px; width: 100%; max-width: 1200px; }
        .card-container { perspective: 1200px; cursor: pointer; height: 250px; }
        .card { width: 100%; height: 100%; position: relative; transform-style: preserve-3d; transition: transform 0.7s; border-radius: 16px; box-shadow: 0 4px 16px rgba(0,0,0,0.08); }
        .card-container.flipped .card { transform: rotateY(180deg); }
        .card-face { position: absolute; width: 100%; height: 100%; backface-visibility: hidden; display: flex; flex-direction: column; box-sizing: border-box; border-radius: 16px; background-color: #fff; padding: 24px; }
        .card-back { background-color: #f0fff4; transform: rotateY(180deg); justify-content: space-between; }
        .card-category { font-size: 14px; color: #0052d9; margin-bottom: 8px; font-weight: 500; }
        .card-question { font-size: 20px; font-weight: 500; flex-grow: 1; display: flex; align-items: center; justify-content: center; text-align: center; }
        .card-answer-wrapper { flex-grow: 1; overflow-y: auto; }
        .card-answer { font-size: 15px; line-height: 1.7; }
        .card-footer { font-size: 13px; color: #8a919f; border-top: 1px solid #f0f0f0; padding-top: 16px; margin-top: 16px; }
        .card-source { font-size: 13px; color: #8a919f; border-top: 1px solid #f0f0f0; padding-top: 12px; margin-top: 12px; }
      </style>
    </head>
    <body>
      <div class="header">
        <h1>Java 并发库中有哪些线程池？它们之间有何区别？ - 学习卡片</h1>
      </div>
      <div class="grid-container">
        
    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">特性</div>
          <div class="card-question">FixedThreadPool 的核心特点是什么？当所有线程都在忙时，新提交的任务会如何被处理？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">特性</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">FixedThreadPool 是一个有固定数量线程的线程池，池中的线程数量是固定的。当所有线程都在忙时，新任务会进入等待队列。</div>
          </div>
          <div class="card-source">来源: 1. FixedThreadPool</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">风险</div>
          <div class="card-question">CachedThreadPool 在何种情况下可能会对系统资源造成巨大压力？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">风险</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">CachedThreadPool 的线程数量没有上限。如果任务持续增长，可能会导致创建过多线程，从而消耗大量系统资源。</div>
          </div>
          <div class="card-source">来源: 2. CachedThreadPool</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">场景</div>
          <div class="card-question">对于需要严格保证任务按提交顺序执行的场景（如订单处理），应该选择哪种线程池？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">场景</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">应该选择 SingleThreadExecutor。因为它是一个只有一个线程的线程池，所有任务会按照提交顺序依次执行。</div>
          </div>
          <div class="card-source">来源: 3. SingleThreadExecutor</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">功能</div>
          <div class="card-question">哪种线程池专门用于处理需要定时或周期性执行的任务？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">功能</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">ScheduledThreadPool 是一个可以定时或周期性执行任务的线程池，它可以指定任务的延迟时间或者周期执行时间。</div>
          </div>
          <div class="card-source">来源: 4. ScheduledThreadPool</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">机制</div>
          <div class="card-question">WorkStealingPool 是如何通过其核心算法来提高多核处理器资源利用率的？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">机制</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">WorkStealingPool 使用了一种称为“工作窃取”（work-stealing）的算法。池中空闲的线程可以窃取其他线程任务队列中的任务来执行，从而最大化 CPU 利用率。</div>
          </div>
          <div class="card-source">来源: 5. WorkStealingPool (Java 8 引入)</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">对比</div>
          <div class="card-question">对于处理大量瞬时且执行时间较短的任务，为什么 CachedThreadPool 通常比 FixedThreadPool 更合适？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">对比</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">因为 CachedThreadPool 是一个会根据需要自动扩展的线程池，能够灵活地创建新线程来快速响应大量短期任务，而 FixedThreadPool 的线程数是固定的，任务堆积时可能导致较长等待时间。</div>
          </div>
          <div class="card-source">来源: 2. CachedThreadPool</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">理论</div>
          <div class="card-question">在 Java 并发编程中使用线程池的核心目的是什么？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">理论</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">使用线程池的主要目的是为了提高系统的性能和资源利用率，避免频繁地创建和销毁线程带来的开销。</div>
          </div>
          <div class="card-source">来源: 文档开篇部分</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">场景</div>
          <div class="card-question">WorkStealingPool 最适合处理哪一类任务？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">场景</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">它适用于计算密集型任务或大规模并行任务，例如数据处理、图像处理等，因为其设计目标是最大化 CPU 利用率。</div>
          </div>
          <div class="card-source">来源: 5. WorkStealingPool (Java 8 引入)</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">特性</div>
          <div class="card-question">CachedThreadPool 中的空闲线程会如何被处理？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">特性</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">在 CachedThreadPool 中，如果一个线程空闲时间超过 60 秒，它就会被销毁。</div>
          </div>
          <div class="card-source">来源: 2. CachedThreadPool</div>
        </div>
      </div>
    </div>

      </div>
    </body>
    </html>
